<template>
  <div id="third">
    <div class="content">
      <el-button type="primary" plain @click="moreFlag=true">载入常用检查</el-button>
      <el-row class="el_t_20">
        <el-col :span="24">
          <el-autocomplete
            class="el_long"
            v-model="info.name"
            :fetch-suggestions="querySearch"
            placeholder="新增检查"
            @select="handleSelect"
          ></el-autocomplete>
        </el-col>
        <el-col :span="24" class="el_t_20">
          <template v-if="list.length > 0">
            <el-table :data="list" :row-class-name="tableRowClassName">
              <el-table-column label="检查项目" prop="name" width="200">
                <template slot-scope="data">
                  <template v-if="data.row.count !== 2">
                    <span class="cell_head" v-html="data.row.name"></span>
                  </template>
                  <template v-else>
                    <el-input type="text" v-model="data.row.name"></el-input>
                  </template>
                </template>
              </el-table-column>
              <el-table-column label="数量" prop="count" width="200">
                <template slot-scope="data">
                  <el-select v-model="data.row.count" placeholder="请选择数量">
                    <el-option :label="1" :value="1"></el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column label="备注" prop="remark" min-width="300">
                <template slot-scope="data">
                  <el-input type="text" placeholder="填写描述"></el-input>
                </template>
              </el-table-column>
              <el-table-column label="单价" width="160">
                <template slot-scope="data">￥{{data.row.no}}</template>
              </el-table-column>
              <el-table-column label="操作" width="80">
                <template slot-scope="data">
                  <el-button type="primary" size="mini" plain @click="deleteItem(data)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </template>
          <template v-else>
            <p class="label">暂无开具新检查项目</p>
          </template>
        </el-col>
        <el-col :span="24">
          <p class="title">历史检查记录单：</p>
          <template v-if="list.length > 0">
            <el-row class="title el_t_20">
              <el-col :span="2" class="title-tag" style="padding-left:10px;">开单时间</el-col>
              <el-col :span="22" class="title-right">
                <el-col :span="6">检查项目</el-col>
                <el-col :span="5">备注</el-col>
                <el-col :span="4">开单医生</el-col>
                <el-col :span="2">金额</el-col>
                <el-col :span="7">操作</el-col>
              </el-col>
            </el-row>
            <template v-for="(item,index) in list">
              <el-row class="list">
                <el-col :span="2" class="text-right title-tag" style="padding: 10px 0;">
                  <div class="state" v-html="times(item.time)"></div>
                </el-col>
                <el-col :span="22" class="line title-right" :class="{active:index===0}">
                  <template v-if="item.list.length > 0" v-for="(itm,idx) in item.list">
                    <div class="line-row">
                      <i v-if="index>0" class="icon_tag"></i>
                      <el-col :span="6">{{itm.name}}</el-col>
                      <el-col :span="5">{{itm.name}}</el-col>
                      <el-col :span="4">{{itm.name}}</el-col>
                      <el-col :span="2">
                        {{itm.name}}
                        <em>×1</em>
                      </el-col>
                      <el-col :span="7">
                        <el-button
                          v-if="index===0"
                          type="primary"
                          plain
                          size="mini"
                          @click="deleteMsg"
                        >取消检查</el-button>
                        <template v-else>
                          <el-button type="primary" plain size="mini">查看报告</el-button>
                          <el-button type="primary" plain size="mini">取消</el-button>
                        </template>
                      </el-col>
                    </div>
                  </template>
                  <el-col :span="24" class="line-label">
                    总计：
                    <em>￥300</em>
                  </el-col>
                  <el-col :span="24">
                    <el-button
                      type="primary"
                      size="mini"
                      plain
                      v-if="index===0"
                      @click="enterMsg"
                    >确认收费</el-button>
                    <el-upload
                      class="upload"
                      action="https://jsonplaceholder.typicode.com/posts/"
                      :show-file-list="false"
                      v-if="index>0"
                    >
                      <el-button size="small" type="text">
                        <i class="el-icon-plus icon_upload"></i>上传报告
                      </el-button>
                    </el-upload>
                    <el-button type="text" size="mini" class="btn_print">
                      <i class="icon_print"></i>打印检查单
                    </el-button>
                  </el-col>
                </el-col>
              </el-row>
            </template>
          </template>
          <template v-else>
            <p class="label">暂无历史检查项目</p>
          </template>
        </el-col>
      </el-row>
      <el-row class="footer-fixed">
        <el-col :span="24" class="text-right">
          <el-upload class="img_upload" action="https://jsonplaceholder.typicode.com/posts/">
            <i class="el-icon-plus avatar-uploader-icon"></i>
            <p>上传</p>
          </el-upload>
          <el-checkbox>
            患者已知签署并成功上传
            <a class="about" href="javascript:void(0);" target="_blank">《杭州泛康诊所知情同意书》</a>
          </el-checkbox>
          <el-button type="primary" plain>取消</el-button>
          <el-button type="primary" :disabled="true" @click="submitInfo('info')">保存</el-button>
        </el-col>
      </el-row>
    </div>
    <div class="mould" :class="{active:moreFlag}">
      <div class="mould-bg"></div>
      <div class="mould-box">
        <div class="mould-title">
          常用检查模板
          <i class="el-icon-close" @click="moreFlag=flase"></i>
        </div>
        <div class="mould-text">
          <el-row style="padding:10px 20px;">
            <el-col :span="12">
              <el-input type="text" placeholder="请输入模板名称查询" class="search-more">
                <el-button slot="append" icon="el-icon-search"></el-button>
              </el-input>
            </el-col>
          </el-row>
          <el-table :data="moreList" :header-row-class-name="'table_header'" class="more-table">
            <el-table-column label="模板名称" prop="name" width="200"></el-table-column>
            <el-table-column label="内容" prop="remark" min-width="300">
              <template slot-scope="data">
                <div class="hidden" v-html="data.row.remark"></div>
              </template>
            </el-table-column>
          </el-table>
          <div class="text-right el_t_20 page_box" v-if="moreList.length > 0">
            <el-pagination
              :current-page="1"
              :page-sizes="[100, 200, 300, 400]"
              :page-size="100"
              layout="prev, pager, next, jumper"
              :total="moreList.length"
            ></el-pagination>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "third",
  data() {
    return {
      search: {
        name: ""
      },
      moreFlag: false,
      info: {
        name: "",
        phone: "",
        sex: "",
        radio: 1,
        list: []
      },
      list: [
        {
          name: "胡忠信",
          sex: "男",
          birthday: "1956-12-10",
          no: "1812100102",
          phone: "15645541321",
          time: "2018-12-10 14:23:32",
          count: "",
          remark: "睡眠障碍睡眠障碍睡眠障碍睡眠障碍睡眠障碍睡眠障碍",
          list: [{ name: "1" }, { name: "2" }]
        },
        {
          name: "胡忠信",
          sex: "男",
          birthday: "1956-12-10",
          no: "1812100102",
          phone: "15645541321",
          time: "2018-12-10 14:23:32",
          count: 1,
          remark: "睡眠障碍睡眠障碍睡眠障碍睡眠障碍睡眠障碍睡眠障碍",
          list: [{ name: "1" }]
        },
        {
          name: "胡忠信",
          sex: "男",
          birthday: "1956-12-10",
          no: "1812100102",
          phone: "15645541321",
          time: "2018-12-10 14:23:32",
          count: 2,
          remark: "睡眠障碍睡眠障碍睡眠障碍睡眠障碍睡眠障碍睡眠障碍",
          list: [{ name: "1" }]
        }
      ],
      restaurants: [
        { value: "三全鲜食（北新泾店）", address: "长宁区新渔路144号" },
        {
          value: "Hot honey 首尔炸鸡（仙霞路）",
          address: "上海市长宁区淞虹路661号"
        },
        {
          value: "新旺角茶餐厅",
          address: "上海市普陀区真北路988号创邑金沙谷6号楼113"
        },
        { value: "泷千家(天山西路店)", address: "天山西路438号" }
      ],
      moreList: [
        {
          name: "睡眠通用量表",
          remark: "爱泼沃、匹兹堡、PHQ-9、GAD-7"
        },
        {
          name: "神经检测",
          remark:
            "神经递质功能检测、多导睡眠系统检测、植物神经功能检神经递质功能检测、多导睡眠系统检测、植物神经功能检"
        }
      ]
    };
  },
  methods: {
    tableRowClassName(row, rowIndex) {
      return "tr_gray";
    },
    times(val) {
      let arr = val.split(" ");
      return `<p class="s_p">${arr[0]}</p><em class="s_e">${arr[1]}</em>`;
    },
    addInfo() {
      this.$router.push({ name: "addOffice" });
    },
    deleteItem(data) {
      this.list.splice(data.$index, 1);
    },
    enterMsg(data) {
      this.$confirm("确定已收取相关费用？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "点错了",
        type: "warning"
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "取消成功!"
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    deleteMsg(data) {
      this.$confirm("确定取消检查？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "点错了",
        type: "warning"
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "取消成功!"
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    querySearch(queryString, cb) {
      var restaurants = this.restaurants;
      var results = queryString
        ? restaurants.filter(this.createFilter(queryString))
        : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    handleSelect(item) {
      console.log(item);
    }
  }
};
</script>

<style scoped>
.content {
  height: calc(100vh - 200px);
  background: #ffffff;
  position: relative;
  padding: 20px;
}
.title {
  color: #999;
  font-size: 14px;
  font-weight: bold;
  margin-top: 20px;
}
.label {
  color: #666;
  font-size: 14px;
  text-indent: 1.5em;
}

.state {
  width: 100%;
  font-size: 12px;
  padding-right: 30px;
}

.state.active {
  color: #ff0000;
}

.list .el-col {
  padding: 5px 0;
  position: relative;
}

.line {
  color: #666;
  font-size: 14px;
}

.line .el-col {
  padding: 10px;
}

.line-row {
  margin-top: 10px;
  overflow: hidden;
  background: #f2f2f2;
  line-height: 30px;
  position: relative;
}

.line-row .el-col:first-child {
  color: #006835;
  font-weight: bold;
}

.line-row .el-col em {
  font-style: normal;
  color: #999;
  font-size: 12px;
}

.line:before {
  content: "";
  display: block;
  width: 1px;
  height: 100%;
  background: #e4e4e4;
  position: absolute;
  left: -20px;
  top: 20px;
}

.line:after {
  content: "";
  display: block;
  width: 9px;
  height: 9px;
  background: #e4e4e4;
  -webkit-border-radius: 20px;
  -moz-border-radius: 20px;
  border-radius: 20px;
  position: absolute;
  left: -24px;
  top: 15px;
}

.line.active:after {
  background: #006835;
}
.icon_print {
  display: inline-block;
  width: 14px;
  height: 14px;
  background: url("./img/print.png") 0 0 no-repeat;
  background-size: 14px 14px;
  vertical-align: middle;
  margin-right: 5px;
  margin-top: -2px;
}
.btn_print {
  color: #666;
}
.line-label {
  font-size: 12px;
}
.line-label em {
  font-style: normal;
  color: #ff9900;
  font-weight: bold;
}
.icon_tag {
  width: 54px;
  height: 34px;
  background: url("./img/tag.png") 0 0 no-repeat;
  background-size: 54px 34px;
  position: absolute;
  left: 15%;
  top: 8px;
  z-index: 9;
}
.icon_upload {
  border: 1px solid #006835;
  border-radius: 3px;
  padding: 1px;
  font-size: 12px;
  margin-right: 5px;
}
.upload {
  float: left;
  height: 30px;
  line-height: 30px;
}
.upload button {
  padding: 0;
  margin-right: 20px;
}
.img_upload {
  float: left;
  margin-left: 220px;
  width: 40px;
  height: 40px;
  background: rgba(242, 242, 242, 1);
  line-height: 16px;
  border: 1px solid rgba(204, 204, 204, 1);
  border-radius: 2px;
  color: #999;
  font-size: 12px;
  text-align: center;
  padding: 0;
}
.img_upload p {
  margin: 0;
}
.about {
  color: #006835;
  margin-right: 20px;
}
.el-input-group__append button {
  background: #fff;
  border-left: 0;
}
.title-tag {
  width: 100px;
}
.title-right {
  width: calc(100% - 100px);
}
</style>
